package charts;
import charts.series.Element;
import flash.display.Sprite;
import flash.geom.Point;
import string.Utils;

class Shape extends Base<Element> {

	var style : { points : Array<{ x : Int, y : Int }> , colour : String , alpha : Float };
	
	public function new( json:Dynamic )
	{
		super();
		this.style = {
			points		: []
			, colour	: '#808080'
			, alpha		: 0.5
		};
		
		Object_helper.merge_2( json, this.style );
		
		this.style.colour = cast string.Utils.get_colour( this.style.colour ); // TODO - colour could be a String and Float, fuck.

		for (val in cast(json.values, Array<{ x:Int , y:Int }>) )
			this.style.points.push( new flash.geom.Point( val.x, val.y ) );
	}
	
	public override function resize( sc:ScreenCoordsBase ): Void {
		
		this.graphics.clear();
		//this.graphics.lineStyle( this.style.width, this.style.colour );
		this.graphics.lineStyle( 0, 0, 0 );
		this.graphics.beginFill( this.style.colour, this.style.alpha );
		
		var moved:Bool = false;
		
		for ( p in this.style.points ) {
			if( !moved )
				this.graphics.moveTo( sc.get_x_from_val(p.x), sc.get_y_from_val(p.y) );
			else
				this.graphics.lineTo( sc.get_x_from_val(p.x), sc.get_y_from_val(p.y) );
			
			moved = true;
		}
		
		this.graphics.endFill();
	}
}

